/*
 * Copyright 2006-2007 Queplix Corp.
 *
 * Licensed under the Modified Queplix BSD License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.queplix.com/BSDLICENSE-1.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.jlect.swebing.ui.client.menu;

import com.jlect.swebing.ui.client.GComponent;
import com.jlect.swebing.ui.client.KeyEvent;
import com.jlect.swebing.ui.client.MouseEvent;
import com.jlect.swebing.ui.client.SelectionController;

import java.util.List;

/**
 * Single selection controller
 *
 * @author Sergey Kozmin
 * @since Nov 27, 2007
 */
public class SingleSelectionController implements SelectionController {
    private GComponent selectedComp;

    public SingleSelectionController() {
    }

    public void addComponent(GComponent item) {
        item.addMouseListener(this);
        item.addKeyListener(this);
    }

    public void removeComponent(GComponent item) {
        item.removeMouseListener(this);
        item.removeKeyListener(this);
    }

    public List getSelection() {
        return null;  //@todo implement me
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
        if(e.getSource() != selectedComp) {
            if(selectedComp != null) {
                selectedComp.focusLost();
            }
            selectedComp = e.getSource();
            if(selectedComp.isEnabled()) {
                selectedComp.requestFocus();
            }
        }
    }

    public void mouseExited(MouseEvent e) {
    }

    public void keyTyped(KeyEvent e) {
        //todo implement reaction on UP, DOWN, PGUP, PGDOWN, LEFT, RIGHT
    }

    public void keyPressed(KeyEvent e) {
    }

    public void keyReleased(KeyEvent e) {
    }
}
